package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class NursingLevelServiceImpl implements NursingLevelService {
    @Autowired
    NursingLevelMapper nursingLevelMapper;

    @Override
    public void delete(Long id) {
        nursingLevelMapper.delete(id);
    }

    @Override
    public NursingLevelVo findById(Long id) {
        NursingLevel nursingLevel = nursingLevelMapper.findById(id);
        NursingLevelVo nursingLevelVo = BeanUtil.toBean(nursingLevel, NursingLevelVo.class);
        return nursingLevelVo;
    }

    @Override
    public void update(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        nursingLevelMapper.update(nursingLevel);
    }

    @Override
    public void insert(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        nursingLevelMapper.insert(nursingLevel);
    }
    @Override
    public List<NursingLevelVo> getNursingLevelList() {
        List<NursingLevel> nursingLevel = nursingLevelMapper.selectAll();
        List<NursingLevelVo> ts = BeanUtil.copyToList(nursingLevel, NursingLevelVo.class);
        return ts;
    }

    @Override
    public PageResponse<NursingLevelVo> getNursingLevelListByPage(String name, Integer pageNum, Integer pageSize, Integer status) {
        PageHelper.startPage(pageNum, pageSize);
        Page<NursingLevel> page=nursingLevelMapper.pageFind(name, status);
        PageResponse<NursingLevelVo> response=PageResponse.of(page, NursingLevelVo.class);
        return response;
    }

    @Override
    public void updateNursingLevelStatus(Integer id, Integer status) {
        nursingLevelMapper.updateStatus(id, status);
    }

}
